{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "authorship_tag": "ABX9TyPJbOtVClyoeFJrkRbVfHup",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/Huangjian2013/ai-demo/blob/main/rag/03-%E5%88%9D%E8%AF%86RAG.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!pip install openai"
      ],
      "metadata": {
        "collapsed": true,
        "id": "4KNXZIpn_oIR"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "import openai\n",
        "import os\n",
        "from google.colab import userdata"
      ],
      "metadata": {
        "id": "lYPV-yOS_0Bu"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "client = openai.OpenAI(api_key = userdata.get('OPEN_AI_KEY'),\n",
        "             base_url = userdata.get('OPEN_AI_BASE_URL'))"
      ],
      "metadata": {
        "id": "fJ6ECEey_21N"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "虽然这里看起来是OPEN_AI的代码，但是实际上用的是Cloudflare的Workers，感谢！"
      ],
      "metadata": {
        "id": "1719eAMPAGFd"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "TixSo0ahGYPA"
      },
      "outputs": [],
      "source": [
        "completion = client.chat.completions.create(\n",
        "  model=\"@cf/meta/llama-2-7b-chat-int8\",\n",
        "  messages=[\n",
        "    {\"role\": \"user\", \"content\": \"介绍一下极越07，请用中文回答\"}\n",
        "  ]\n",
        ")\n",
        "\n",
        "print(completion.choices[0].message)"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "knowledge = \"\"\"极越07是极越旗下第一款轿车，定位为AI智能纯电轿车。\n",
        "极越07采用了更为时尚的溜背式轿跑设计，车身高光线也贯穿整车侧身，用简约的设计风格展现了车身的型面美感。具备智能AI像素大灯与车内外语音功能。\n",
        "2023年12月26日，极越宣布旗下定位“最美智能掀背轿车”的第二款量产车正式定名“极越07”并计划于明年上市。\n",
        "2024年4月25日，极越汽车旗下第二款车型——AI智能纯电轿车极越07首次亮相。\n",
        "该车型凭借独特的设计，荣获2023年德国红点、iF两项设计大奖。虽然关于该车型的消息尚不丰富，但其获奖的设计实力已经引人瞩目。\n",
        "极越07是极越的第二款车型，其延续了极越家族的设计基因，整体线条圆润流畅又不失动感，整体的比例也十分协调。细节方面，低风阻的轮圈配以小尺寸的外后视镜以及隐藏式的门把手，能帮助新车降低风阻。\n",
        "新车的前脸采用了电动车常见的封闭式设计，车头部分的一体感非常强。同时通过线条的起伏又带来了不错的立体感，流畅的日间行车灯非常潇洒。\n",
        "极越07采用环抱式的内饰，并加入了炫彩的氛围灯，方向盘采用半辐式的设计，同时车内配备一块贯穿式屏幕，整车内部拥有非常简约的氛围，符合当前市场的流行趋势。\n",
        "极越07配备了智能AI像素大灯与车内外语音功能，让用户与AI智能伙伴SIMO进行人性化的交流与情绪表达.\n",
        "据了解，极越07采用掀背式设计，可提供更宽裕的后备箱空间。此外，该车型配备智能AI像素大灯与车内外语音功能，\n",
        "同时还搭载国内首个纯视觉高阶智驾技术，解决车顶瞭望塔式激光雷达破坏整车曲线美和低风阻设计的弊端.\n",
        "极越 07 搭载威睿电动汽车技术（宁波）有限公司提供的电动机，高配车型为双电机，标准版为单电机，单电机峰值功率为 200 千瓦。\n",
        "电池配置上，极越 07 的 71.4 千瓦时电池车型工信部纯电续航里程为 660 公里，而 100 千瓦时电池车型续航里程则有 770 公里（四驱）和 880 公里（后驱）两种选择\"\"\"\n"
      ],
      "metadata": {
        "id": "-iG5Btlu_lzw"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "completion = client.chat.completions.create(\n",
        "  model=\"@cf/meta/llama-2-7b-chat-int8\",\n",
        "  messages=[\n",
        "    {\"role\": \"user\", \"content\": \"请根据以下提供的内容，介绍一下极越07，一定要用中文回答。提供的内容：\" + knowledge}\n",
        "  ]\n",
        ")\n",
        "\n",
        "print(completion.choices[0].message)"
      ],
      "metadata": {
        "id": "Qfj6p5S8GIfB"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "completion = client.chat.completions.create(\n",
        "  model=\"@cf/meta/llama-2-7b-chat-int8\",\n",
        "  messages=[\n",
        "    {\"role\": \"user\", \"content\": \"请根据以下提供的内容回答：极越07的续航是多少？一定要用中文回答。提供的内容：\" + knowledge}\n",
        "  ]\n",
        ")\n",
        "\n",
        "print(completion.choices[0].message)"
      ],
      "metadata": {
        "id": "picuJ_GTGPZX"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}